#include<stdio.h>
#include<string.h>                                                              
#include<unistd.h>
#include<fcntl.h>
#include<sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include<stdlib.h>


#define CLIENT_PORT 8000
#define CLIENT_IP "127.0.0.1"
#define SERVER_PORT 8000
#define SERVER_IP "127.0.0.1"

#define BUFSIZE 1024 

int main(int argc, char* argv[])
{
    int cfd = socket(AF_INET,SOCK_STREAM,0);

    struct sockaddr_in client_addr;
    client_addr.sin_family = AF_INET;
    client_addr.sin_port = htons(CLIENT_PORT);
    int dst;
    inet_pton(AF_INET,CLIENT_IP,(void*)&dst);
    client_addr.sin_addr.s_addr = dst;  //整数，大端字节数

    bind(cfd,(struct sockaddr*)&client_addr,sizeof(client_addr));

    struct sockaddr_in server_addr;
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SERVER_PORT);
    inet_pton(AF_INET,SERVER_IP,(void*)&dst);
    server_addr.sin_addr.s_addr = dst; //整数，大端字节数

    //建立连接
    connect(cfd,(struct sockaddr*)&server_addr,sizeof(server_addr));
    
    char buf[BUFSIZE];

    write(cfd,"hello server",12);
    while(1);

    return 0;
}
